const db = uniCloud.database()

// 获取APPID
function getWxAppid(type) {
	if (type == 'wx') {
		return 'wx9ac8eecf404e43f1'
	}
	if (type == 'qq') {
		return '1109630247'
	}
}
// 获取Secret
function getSecret(type) {
	if (type == 'wx') {
		return 'a5b082cce4eee32e86ab43a46ba91229'
	}

	if (type == 'qq') {
		return 'WK3HzIDkcLLjTxDX'
	}

}
// 获取access_token
function getAccessToken(type) {
	return new Promise(async resolve => {
		const collection = db.collection('wxinfo')
		if (type == 'wx') {
			let res, access_token
			res = await collection.where({
				_id: '5e9b1dc2d83f84004d43a61e'
			}).get()
			access_token = res.data[0].accesstoken
			resolve(access_token)
		}
		if (type == 'qq') {
			let res, access_token
			res = await collection.where({
				_id: '5e9ee85bd2993e004d771c2d'
			}).get()
			access_token = res.data[0].accesstoken
			resolve(access_token)
		}
	})
}
// 微信图片鉴权
async function WximgSecCheck(imginfo) {
	let access_token = await getAccessToken()
	return new Promise(async resolve => {
		let result = await uniCloud.httpclient.request(
			`https://api.weixin.qq.com/wxa/img_sec_check?access_token=${access_token}`, {
				dataType: 'json',
				method: 'POST',
				data: {
					media: imginfo
				}
			})
	})
}


module.exports = {
	WximgSecCheck,
	getWxAppid,
	getSecret,
	getAccessToken
}
